#include "cmatrix.h"

CMatrix::CMatrix(float a, float b, float c, float d, float e, float f, float g, float h, float i)
{
    this->m_Mat[0]= a;
    this->m_Mat[1]= b;
    this->m_Mat[2]= c;
    this->m_Mat[3]= d;
    this->m_Mat[4]= e;
    this->m_Mat[5]= f;
    this->m_Mat[6]= g;
    this->m_Mat[7]= h;
    this->m_Mat[8]= i;
}

CMatrix::CMatrix(const CMatrix & M)
{
    this->m_Mat[0]= M.m_Mat[0];
    this->m_Mat[1]= M.m_Mat[1];
    this->m_Mat[2]= M.m_Mat[2];
    this->m_Mat[3]= M.m_Mat[3];
    this->m_Mat[4]= M.m_Mat[4];
    this->m_Mat[5]= M.m_Mat[5];
    this->m_Mat[6]= M.m_Mat[6];
    this->m_Mat[7]= M.m_Mat[7];
    this->m_Mat[8]= M.m_Mat[8];
}

float CMatrix::at(unsigned i)
{
    return this->m_Mat[i];
}

void CMatrix::operator =(const CMatrix & M)
{
    this->m_Mat[0]= M.m_Mat[0];
    this->m_Mat[1]= M.m_Mat[1];
    this->m_Mat[2]= M.m_Mat[2];
    this->m_Mat[3]= M.m_Mat[3];
    this->m_Mat[4]= M.m_Mat[4];
    this->m_Mat[5]= M.m_Mat[5];
    this->m_Mat[6]= M.m_Mat[6];
    this->m_Mat[7]= M.m_Mat[7];
    this->m_Mat[8]= M.m_Mat[8];
}

CMatrix CMatrix::operator*(const CMatrix & M)
{
    return CMatrix( this->at(0)*M.m_Mat[0] + this->at(1)*M.m_Mat[3] + this->at(2)*M.m_Mat[6],/**/ this->at(0)*M.m_Mat[1] + this->at(1)*M.m_Mat[4] + this->at(2)*M.m_Mat[7],/**/ this->at(0)*M.m_Mat[2] + this->at(1)*M.m_Mat[5] + this->at(2)*M.m_Mat[8],
                    this->at(3)*M.m_Mat[0] + this->at(4)*M.m_Mat[3] + this->at(5)*M.m_Mat[6],/**/ this->at(3)*M.m_Mat[1] + this->at(4)*M.m_Mat[4] + this->at(5)*M.m_Mat[7],/**/ this->at(3)*M.m_Mat[2] + this->at(4)*M.m_Mat[5] + this->at(5)*M.m_Mat[8],
                    this->at(6)*M.m_Mat[0] + this->at(7)*M.m_Mat[3] + this->at(8)*M.m_Mat[6],/**/ this->at(6)*M.m_Mat[1] + this->at(7)*M.m_Mat[4] + this->at(8)*M.m_Mat[7],/**/ this->at(6)*M.m_Mat[2] + this->at(7)*M.m_Mat[5] + this->at(8)*M.m_Mat[8]);
}

CVector3f CMatrix::operator*(const CVector3f & V)
{
    return CVector3f(this->at(0)*V.m_fX + this->at(1)*V.m_fY + this->at(2)*V.m_fZ,
                      this->at(3)*V.m_fX + this->at(4)*V.m_fY + this->at(5)*V.m_fZ,
                      this->at(6)*V.m_fX + this->at(7)*V.m_fY + this->at(8)*V.m_fZ);
}

CPoint3f CMatrix::operator*(CPoint3f & P)
{
    return CPoint3f(this->at(0)*P.GetX() + this->at(1)*P.GetY() + this->at(2)*P.GetZ(),
                    this->at(3)*P.GetX() + this->at(4)*P.GetY() + this->at(5)*P.GetZ(),
                    this->at(6)*P.GetX() + this->at(7)*P.GetY() + this->at(8)*P.GetZ());
}
